#include<stdio.h>
#include<string.h>
#include<string>
#include<iostream>
using namespace std;
struct na
{
	string a;
	int c;
	int m;
	int e;
};
void in(struct na *k)
{
	cin>>(k->a)>>(k->c)>>(k->m)>>(k->e);
}
int ifq(struct na p1,struct na p2)
{
	int ret=1;
	int c1=p1.c,c2=p2.c;
	int m1=p1.m,m2=p2.m;
	int e1=p1.e,e2=p2.e;
	if(c1-c2>5||c1-c2<-5) ret=0;
	if(m1-m2>5||m1-m2<-5) ret=0;
	if(e1-e2>5||e1-e2<-5) ret=0;
	if((c1+m1+e1)-(c2+m2+e2)>10||(c1+m1+e1)-(c2+m2+e2)<-10) ret=0;
	return ret;
}
int main()
{
	struct na p[1001];
	int i,n,j;
	scanf("%d",&n);
	for(i=1;i<=n;i++) in(&p[i]);
	for(i=1;i<n;i++)
	{
		for(j=i+1;j<=n;j++)
		{
			if(ifq(p[i],p[j])) cout<<p[i].a<<" "<<p[j].a<<endl; 
		};
	};
	return 0;
}

